import java.io.*;
import java.util.Arrays;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-10-07
 * Time: 14:17
 */
public class Spiralarray_2 {
    static PrintWriter out=new PrintWriter(System.out);
    static BufferedReader ins=new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in=new StreamTokenizer(ins);

    public static void main(String[] args) throws IOException {
        in.nextToken();
        int n=(int) in.nval;
        int[] nums=new int[n];
        int M=0;int N=0;
        for (int i = (int) Math.sqrt(n); i>=1  ; i--) {
            //从大往小遍历，遇到大的直接break，因为i越大，M=n/i和N的差距越小
            if(n%i==0){
                M=n/i;//M大一些
                N=i;
                break;
            }
        }
        for (int i = 0; i < n; i++) {
            in.nextToken();
            nums[i]=(int) in.nval;
        }
        int[][] ans=new int[M][N];
        Arrays.sort(nums);
        int top=0;int bottom=M-1;int left=0;int right=N-1;
        int j=n-1;
        while (true){
            for (int i = left; i <=right ; i++) {
                ans[top][i]=nums[j];
                j--;
            }
            top++;
            if(top>bottom)break;

            for (int i = top; i <=bottom ; i++) {
                ans[i][right]=nums[j];
                j--;
            }
            right--;
            if(right<left)break;

            for (int i = right; i >=left ; i--) {
                ans[bottom][i]=nums[j];
                j--;
            }
            bottom--;
            if(bottom<top)break;

            for (int i = bottom; i >=top ; i--) {
                ans[i][left]=nums[j];
                j--;
            }
            left++;
            if(left>right)break;
        }
        for (int i = 0; i <M ; i++) {
            for (int k = 0; k <N-1 ; k++) {
                out.print(ans[i][k]+" ");
            }
            out.println(ans[i][N-1]);
        }
        out.flush();
    }
}
